package com.mark.base.controller;

import com.mark.base.pojo.Label;
import com.mark.base.service.LabelService;
import com.mark.entity.Result;
import com.mark.entity.StatusCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
//import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @Author Markburt
 * @Description :
 *      <p>CrossOrigin 跨域</p>
 *      <p>RefreshScope 热加载</p>
 * @DATE: 6/8/2020
 * @TIME: 1:27 PM
 * @YEAR: 2020
 * @Version :
 **/
@RestController
@RequestMapping("/label")
@CrossOrigin
//@RefreshScope
public class LabelController {


    @Autowired
    private LabelService labelService;

    @Autowired
    private HttpServletRequest request;

    @Value("${ip}")
    private String ip;

/**
 * @param  label|必填
 *
 * @return 当前返回的基本信息
 * @resp code 返回码 |string|必填
 * @resp msg  |string
 * @resp  查询成功后返回 信息|string
 */
    @PostMapping("")
    public Result save(@RequestBody Label label) {
        labelService.save(label);
        return new Result(true, StatusCode.OK, "保存成功!!");
    }

    @GetMapping("")
    public Result findAll(){
        System.out.println("ip为："+ip);
        //获取头信息
        String header = request.getHeader("Authorization");
        System.out.println(header);

        List<Label> list = labelService.findAll();
        return new Result(true,StatusCode.OK,  "查询成功", list);
    }


}
